#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int book[10];


int n = 4;

void dfs(int k) {
    if (k >= n) {//叶子结点
        for (int i = 0; i < n; i++) {
            cout << a[i] << " ";

        }
        cout << endl;


        return;
    }
    //递归部分 表示还没有到达终点
    for (int i = 1; i <= n; i++) {
        if (book[i] == 1)continue;

        a[k] = i;
        book[i] = 1;//标记i已经使用过
        dfs(k + 1);
        book[i] = 0;

    }


}


int main() {
    dfs(0);
    return 0;
}